<script type="text/javascript">
function show()
{
	document.adfrm.action="index.php?tc=classifieds_ads_add";
	document.adfrm.submit();
}
</script>
<form name="adfrm" method="post" action="#">
<table border="0" width="100%" align="center">
<tr>
	<td align="left"><span style="color:#1B78B7; font-size:14px; font-weight:bold">Ads</span>&nbsp;
	</td>
    <td width="90%" align="right" class="font12">
    <a href="index.php?tc=classifieds_ads_add" class="font12">Add Ads</a>  
    <!--<a href="index.php?tc=addcity" class="font12">Add City</a>-->
    </td>
	<td align="right">
    	<select name="_st" onChange="window.location='index.php?tc=classifieds_ads&page=<?php echo $_REQUEST['page'];?>&_st='+this.value">
        	<option value="" <?php if($_REQUEST['_st']=="") echo "selected";?>><--Sort--></option>
            <option value="2" <?php if($_REQUEST['_st']==2) echo "selected";?>>All</option>
            <option value="1" <?php if($_REQUEST['_st']==1) echo "selected";?>>Approved Ads</option>
            <option value="3" <?php if($_REQUEST['_st']==3) echo "selected";?>>Pending Ads</option>
        </select>	    
    </td>
</tr>
<tr>
	<td background="images/topline.gif" colspan="2" height="11"></td>
</tr>    
</table>
</form> 
	<?php
if($_REQUEST['_s'] == 2)
{ ?>
	<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Deleted Successfully</div></td>
    </tr>    
    </table>
<?php } ?>
<table width="100%" align="center" border="0" class="list">
<thead>
<tr>
	<td align="center" width="30">#</td>
	<td align="center" width="250">Item Name</td>
    <td align="center" width="200">Category</td>
    <td align="center" width="150">Sub Category</td>
    <td align="center" width="150">Date</td>
    <td align="center" width="100">Status</td>
    <td align="center"  width="100">Action</td>
</tr>
</thead>
<?php
include('includes/function.php');
$self="index.php?tc=classifieds_ads&_st=".$_REQUEST['_st'];
$rowsPerPage = 20;
$pageNum = 1;
if(isset($_GET['page']))
{
	$pageNum = $_GET['page'];
}
if($_GET['page']=="")
{
	$pageNum = 1;
}

/*<!--counting the offset-->*/
$offset = ($pageNum - 1) * $rowsPerPage;
$st = $_REQUEST['_st'];

if($st == "" || $st == 2)
{
	$res = mysql_query("select Id from classifieds_ads where TransactionId<>''");
	
	$query = mysql_query("select a.Item, a.Id, b.category,sub_cat_name, DATE_FORMAT(InsertedDate,'%d-%m-%Y') as insdate, Status 
						 from classifieds_ads a inner join classifieds_category b on (a.Category = b.id AND b.active_status = '1')
						 inner join classifieds_subcategory c on (a.sub_category = c.id AND c.active_status = '1')
						 where TransactionId<>'' order by Id desc limit $offset , $rowsPerPage") or die(mysql_error());
}
else
{
	if($st == 3) $st=0;
	$res = mysql_query("select Id from classifieds_ads where Status='$st' and TransactionId<>''");
	
	$query = mysql_query("select a.Item, a.Id, b.category,sub_cat_name, DATE_FORMAT(InsertedDate,'%d-%m-%Y') as insdate, Status 
						 from classifieds_ads a inner join classifieds_category b on (a.Category = b.id AND b.active_status = '1')
						 inner join classifieds_subcategory c on (a.sub_category = c.id AND c.active_status = '1')
						 where Status='$st' and TransactionId<>'' 
						 order by Id desc limit $offset , $rowsPerPage");
}
$i = 1;
while($q = mysql_fetch_array($query))
{ 

	if($q["Status"] == 1) $status = "Approved";
	else $status = "Pending";
	?>
    <tr class="font12">
        <td align="center"><?php echo $i+$offset;?></td>
        <td align="left"><?php echo $q["Item"];?></td>
        <td align="left"><?php echo $q["category"];?></td>
        <td align="center"><?php echo $q["sub_cat_name"];?></td>
        <td align="center"><?php echo $q["insdate"];?></td>
        <td align="center"><?php echo $status;?></td>
        <td align="center"><a href="index.php?tc=classifieds_ads_view&_d=<?php echo $q['Id'];?>&page=<?php echo $pageNum;?>" class="font12">Edit</a>&nbsp;
        	<a href="index.php?tc=classifieds_ads_view&_d=<?php echo $q['Id'];?>&page=<?php echo $pageNum;?>&_a=d" onclick="return confirm('Are you sure want to delete?')" class="font12">Delete</a>
        </td>
   	</tr>     
<?php 
	$i++;
}
?>
<?php 
if(mysql_num_rows($res) <= $rowsPerPage){	}
else { ?>
<tr>
    <td colspan="7" align="center"  bgcolor="#E3ECF3">
        <?php echo $paginglink=getPagingLink($res, $rowsPerPage,$pageNum,$self); ?>	
    </td>
</tr>
<?php } ?>
</table>    